package com.trg.designmodel.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: Universtiy
 * @Description: Composite需要管理子类，
 * @Author: tangrg
 * @Date: 2021/7/7 11:34
 * @Version: 1.0
 * @Return:
 **/
public class College extends OrganizationComponent {
    //List中存放的是Department
    List<OrganizationComponent> organizationComponents = new ArrayList<>();

    public College(String name, String desc) {
        super(name, desc);
    }

    @Override
    public void add(OrganizationComponent organizationComponent) {
        organizationComponents.add(organizationComponent);
    }

    @Override
    public void remove(OrganizationComponent organizationComponent) {
        organizationComponents.remove(organizationComponent);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public String getDesc() {
        return super.getDesc();
    }

    /**
     * 输出University中包含的college
     */
    @Override
    protected void print() {
        System.out.println("--------------" + getName() + "--------------");
        //遍历 organizationComponents
        for (OrganizationComponent organizationComponent : organizationComponents) {
            organizationComponent.print();
        }
    }
}
